﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;

using System.Web.Http;
using Microsoft.Practices.Unity;
using Newtonsoft.Json;
using RestSharp;
using Ymatou.CommonService;
using Ymatou.PerfMonitorClient;
using Ymatou.ServiceCenter;
using YmatouSeller.Common.API;
using YmatouSeller.Notice.ApplicationService.Interface;
using YmatouSeller.NoticeAPI.Model.Request;
using YmatouSeller.NoticeAPI.Model.Response;

namespace YmatouSeller.Notice.API.Controllers
{
    public class QueryNoticeController : BaseController
    {
        /// <summary>
        /// 获取通知未读数1
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [ServiceRegister("api/QueryNotice/GetUnReadNoticeCount", Method.GET)]
        [HttpGet]
        public BaseResponseModel<GetUnReadNoticeCountResponse> GetUnReadNoticeCount([FromUri] GetUnReadNoticeCountRequest request)
        {
            using (MethodMonitor.New("api/QueryNotice/GetUnReadNoticeCount"))
            {
        
                try
                {
                    ApplicationLog.Info(string.Format("api/QueryNotice/GetUnReadNoticeCount请求Request：{0}", JsonConvert.SerializeObject(request)));
                    var response = new GetUnReadNoticeCountResponse();
                    request.Validate();
                    string sContinent = this.systemNoticeManageService.GetSellerInfo(request.SellerId);
                    response.UnReadNoticeCount = this.systemNoticeManageService.GetUnReadNoticeCount(sContinent,
                        request.SellerId);
                    ApplicationLog.Info(string.Format("api/NoticeManage/GetMoveNoticeList请求Response：{0}", JsonConvert.SerializeObject(response)));
                    return new SuccessResponseModel<GetUnReadNoticeCountResponse>(response);
                }
                catch (Ymatou.API.Common.BussniessException ex)
                {
                    ApplicationLog.Info(string.Format("api/QueryNotice/GetUnReadNoticeCount业务异常：Code={0},Msg={1}", ex.ErrorCode, ex.ErrorMsg));
                    return new BussniessErrorResponseModel<GetUnReadNoticeCountResponse>(int.Parse(ex.ErrorCode), ex.ErrorMsg);
                }
                catch (Exception ex)
                {
                    ApplicationLog.Error("api/QueryNotice/GetUnReadNoticeCount异常", ex);
                    return new SystemErrorResponseModel<GetUnReadNoticeCountResponse>(ex.Message);
                }
            }
        }

        /// <summary>
        /// 获取跑马灯LIST111
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [ServiceRegister("api/QueryNotice/GetMoveNoticeList", Method.GET)]
        [HttpGet]
        public BaseResponseModel<GetMoveNoticeListResponse> GetMoveNoticeList([FromUri] GetMoveNoticeListRequest request)
        {
            using (MethodMonitor.New("api/QueryNotice/GetMoveNoticeList"))
            {
                try
                {
                    ApplicationLog.Info(string.Format("api/QueryNotice/GetMoveNoticeList请求Request：{0}", JsonConvert.SerializeObject(request)));
                    request.Validate();
                    var response = new GetMoveNoticeListResponse();
                    string sContinent = this.systemNoticeManageService.GetSellerInfo(request.SellerId);
                    response.NoticeList = systemNoticeManageService.GetMoveNoticeList(sContinent, request.SellerId);

                    ApplicationLog.Info(string.Format("api/QueryNotice/GetMoveNoticeList请求Response：{0}", JsonConvert.SerializeObject(response)));
                    return new SuccessResponseModel<GetMoveNoticeListResponse>(response);
                }
                catch (Ymatou.API.Common.BussniessException ex)
                {
                    ApplicationLog.Info(string.Format("api/QueryNotice/GetMoveNoticeList业务异常：Code={0},Msg={1}", ex.ErrorCode, ex.ErrorMsg));
                    return new BussniessErrorResponseModel<GetMoveNoticeListResponse>(int.Parse(ex.ErrorCode), ex.ErrorMsg);
                }
                catch (Exception ex)
                {
                    ApplicationLog.Error("api/QueryNotice/GetMoveNoticeList异常", ex);
                    return new SystemErrorResponseModel<GetMoveNoticeListResponse>(ex.Message);
                }
            }
        }

        /// <summary>
        /// 获取买手后台首页通知LIST
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [ServiceRegister("api/QueryNotice/GetSellerAllNoticeList", Method.GET)]
        [HttpGet]
        public BaseResponseModel<GetSellerAllNoticeListResponse> GetSellerAllNoticeList([FromUri] GetSellerAllNoticeListRequest request)
        {
            using (MethodMonitor.New("api/QueryNotice/GetSellerAllNoticeList"))
            {
                try
                {
                    ApplicationLog.Info(string.Format("api/QueryNotice/GetSellerAllNoticeList请求Request：{0}", JsonConvert.SerializeObject(request)));
                    request.Validate();
                    var response = new GetSellerAllNoticeListResponse();
                   string sContinent = this.systemNoticeManageService.GetSellerInfo(request.SellerId);
                   response.NoticeList = systemNoticeManageService.GetSellerAllNoticeList(sContinent, request.SellerId, request.NoticeType, request.Total);

                    ApplicationLog.Info(string.Format("api/QueryNotice/GetSellerAllNoticeList请求Response：{0}", JsonConvert.SerializeObject(response)));
                    return new SuccessResponseModel<GetSellerAllNoticeListResponse>(response);
                }
                catch (Ymatou.API.Common.BussniessException ex)
                {
                    ApplicationLog.Info(string.Format("api/QueryNotice/GetSellerAllNoticeList业务异常：Code={0},Msg={1}", ex.ErrorCode, ex.ErrorMsg));
                    return new BussniessErrorResponseModel<GetSellerAllNoticeListResponse>(int.Parse(ex.ErrorCode), ex.ErrorMsg);
                }
                catch (Exception ex)
                {
                    ApplicationLog.Error("api/QueryNotice/GetSellerAllNoticeList异常", ex);
                    return new SystemErrorResponseModel<GetSellerAllNoticeListResponse>(ex.Message);
                }
            }
        }
        /// <summary>
        /// 获取买手后台更多noticeLIST
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
       [ServiceRegister("api/QueryNotice/GetSystemNoticeDetailList", Method.GET)]
        [HttpGet]
        public BaseResponseModel<GetSystemNoticeDetailListResponse> GetSystemNoticeDetailList([FromUri] GetSystemNoticeDetailListRequest request)
        {
            using (MethodMonitor.New("api/QueryNotice/GetSystemNoticeDetailList"))
            {
                try
                {
                    ApplicationLog.Info(string.Format("api/QueryNotice/GetSystemNoticeDetailList请求Request：{0}", JsonConvert.SerializeObject(request)));
                    request.Validate();
                    var response = new GetSystemNoticeDetailListResponse();
                    int total = 0;
                    string sContinent = this.systemNoticeManageService.GetSellerInfo(request.SellerId);
                    response.SystemNoticeTypeEntityList = systemNoticeManageService.GetSystemNoticeDetailList(request.SellerId, sContinent, request.NoticeType, request.BeginTime, request.EndTime, request.PageIndex, request.PageSize, out total);
            
                    ApplicationLog.Info(string.Format("api/QueryNotice/GetSystemNoticeDetailList请求Response：{0}", JsonConvert.SerializeObject(response)));
                    return new SuccessResponseModel<GetSystemNoticeDetailListResponse>(response);
                }
                catch (Ymatou.API.Common.BussniessException ex)
                {
                    ApplicationLog.Info(string.Format("api/QueryNotice/GetSystemNoticeDetailList业务异常：Code={0},Msg={1}", ex.ErrorCode, ex.ErrorMsg));
                    return new BussniessErrorResponseModel<GetSystemNoticeDetailListResponse>(int.Parse(ex.ErrorCode), ex.ErrorMsg);
                }
                catch (Exception ex)
                {
                    ApplicationLog.Error("api/QueryNotice/GetMoveNoticeList异常", ex);
                    return new SystemErrorResponseModel<GetSystemNoticeDetailListResponse>(ex.Message);
                }
            }
        }

       /// <summary>
       /// 获取类型LIST
       /// </summary>
       /// <param name="request"></param>
       /// <returns></returns>
       [ServiceRegister("api/QueryNotice/GetNoticeTypeList", Method.GET)]
       [HttpGet]
       public BaseResponseModel<GetNoticeTypeListResponse> GetNoticeTypeList([FromUri] GetNoticeTypeListRequest request)
       {
           using (MethodMonitor.New("api/QueryNotice/GetNoticeTypeList"))
           {
               try
               {
                   ApplicationLog.Info(string.Format("api/QueryNotice/GetNoticeTypeList请求Request：{0}", JsonConvert.SerializeObject(request)));
                   request.Validate();
                   var response = new GetNoticeTypeListResponse();

                   string sContinent = this.systemNoticeManageService.GetSellerInfo(request.Sellerid);
                   response.NoticeTypeList = systemNoticeManageService.GetNoticeTypeList(request.Sellerid, sContinent);

                   ApplicationLog.Info(string.Format("api/QueryNotice/GetNoticeTypeList请求Response：{0}", JsonConvert.SerializeObject(response)));
                   return new SuccessResponseModel<GetNoticeTypeListResponse>(response);
               }
               catch (Ymatou.API.Common.BussniessException ex)
               {
                   ApplicationLog.Info(string.Format("api/QueryNotice/GetNoticeTypeList业务异常：Code={0},Msg={1}", ex.ErrorCode, ex.ErrorMsg));
                   return new BussniessErrorResponseModel<GetNoticeTypeListResponse>(int.Parse(ex.ErrorCode), ex.ErrorMsg);
               }
               catch (Exception ex)
               {
                   ApplicationLog.Error("api/QueryNotice/GetMoveNoticeList异常", ex);
                   return new SystemErrorResponseModel<GetNoticeTypeListResponse>(ex.Message);
               }
           }
       }
    }
}
